<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎注册</title>
    <link href="css/register.css" rel="stylesheet">
</head>
<body>

<div class="form-div">
    <div class="reg-content">
        <h1>欢迎注册</h1>
        <span>已有帐号？</span> <a href="login.jsp">登录</a>
    </div>
                        <%--跳转到注册的服务器--%>
    <form id="reg-form" action="userRegister" method="post">
        <table>
            <tr>
                <td>用户名</td>
                <td class="inputs">
                    <input name="username" type="text" id="username">
                    <br>
                    <span id="username_err" class="err_msg">${error}</span>
                </td>
            </tr>

            <tr>
                <td>密码</td>
                <td class="inputs">
                    <input name="password" type="password" id="password">
                    <br>
                    <span id="password_err" class="err_msg" style="display: none">密码格式有误</span>
                </td>
            </tr>

            <tr>
                <td>验证码</td>
                <td class="inputs">
                    <input name="checkCode" type="text" id="checkCode">
                    <img id="checkCodeImg" src="checkCodeServlet">
                    <%--点击重写生成验证码跳转到js代码--%>
                    <a href="javaScript:changeCheckCode();" id="changeImg" >看不清？</a>
                </td>
            </tr>
        </table>

        <div class="buttons">
            <input value="注 册" type="submit" id="reg_btn">
        </div>
        <br class="clear">
    </form>
</div>

</body>
</html>
<script>
    function changeCheckCode() {
        //生成一个随机数
        let number = Math.random();
        //地址参数带一个请求数据浏览器会以为是一次新的请求就会重新生成验证码  如果不带不同的参数浏览器会认为是同一种请求不会跳转
        document.getElementById("checkCodeImg").src = "checkCodeServlet?code=" + number;
    }
</script>